chapter 9

note

tuple is an example of a data structure — a mechanism for grouping and organizing data to make it easier to use.

a=(a,b,c,d)
a[0]---a
a[1]---b
a[2]---c

slice:a[:1]---a,b

>>> tup = (5,)
>>> type(tup)
<class 'tuple'>
>>> x = (5)
>>> type(x)
<class 'int'>
 

packing & no packing
a=(a,b,c)packing

each of those in turn can be another tuple, a list, a string, or any other kind of Python value. This property is known as being heterogeneous, meaning that it can be composed of elements of different types.

exercise

1.
def tuple_can_be_arguement(n):
    return n
print(tuple_can_be_arguement(('a','b')))
2.
tuple a generalization of a pair
3.

pair is a kind of tuple